package com.hh.service.service.impl.integral;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.hh.common.model.integral.PointsMallCategory;
import com.hh.common.response.integral.IntegralCateListResponse;
import com.hh.service.dao.integral.PointsMallCategoryDao;
import com.hh.service.service.integral.PointsMallCategoryService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class PointsMallCategoryServiceImpl implements PointsMallCategoryService {

    @Resource
    private PointsMallCategoryDao dao;

    @Override
    public PointsMallCategory getItemById(Integer id) {
        return dao.selectById(id);
    }

    @Override
    public List<IntegralCateListResponse> getList() {
        LambdaQueryWrapper<PointsMallCategory> objectLambdaQueryWrapper = Wrappers.lambdaQuery();
        objectLambdaQueryWrapper.orderByAsc(PointsMallCategory::getSort);
        List<PointsMallCategory> pointsMallCategories = dao.selectList(objectLambdaQueryWrapper);
        List<IntegralCateListResponse> list = new ArrayList<>();
        if(pointsMallCategories.size() > 0){
            for (PointsMallCategory pointsMallCategory : pointsMallCategories) {
                IntegralCateListResponse integralCateListResponse = new IntegralCateListResponse();
                BeanUtil.copyProperties(pointsMallCategory,integralCateListResponse);
                list.add(integralCateListResponse);
            }
        }
        return list;
    }
}
